﻿using System.Reflection;

namespace Sapit.Helpers
{
    public class Invocation
    {
        public object InvocationTarget { get; set; }
        public MethodBase Method { get; set; }

        public override bool Equals(object obj)
        {
            var o = obj as Invocation;
            return o.InvocationTarget == InvocationTarget &&
                   o.Method == Method;
        }

        public override int GetHashCode()
        {
            int result = 0;
            foreach (char c in Method.Name)
            {
                result += c;
            }
            foreach (var p in Method.GetParameters())
            {
                foreach (char c in p.Name)
                {
                    result += c;
                }
            }
            result += InvocationTarget.GetHashCode();
            return result;
        }
    }
}
